﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Messaging;

namespace queue
{
    class MessageProcess
    {
        public const string queuename = ".\\private$\\testQueue";//队列名称
        //public MessageQueue MsgQue;
        public MessageQueue InitMessage()
        {            
            if (MessageQueue.Exists(queuename))
            {
               return new System.Messaging.MessageQueue(queuename);
            }
            else
            {
                return MessageQueue.Create(queuename);
            }
        }
        public void testMessage(string msg)
        {
            MessageQueue MsgQue = InitMessage();
            //if (!MessageQueue.Exists(queuename))
            //{
            //    InitMessage();
            //}
            
            Message m = new Message();
            m.Label = "我的消息";      //描述消息的字串
            m.Body = msg;        //消息的主体
            MsgQue.Send(m);                      //发送
        }
        
    }
}
